home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / pictetri.src / pictetri / pictetris-src / utils.c < prev    next >
C/C++ Source or Header  |  1995-12-19  |  4KB  |  112 lines

  1. /***************************************************************************\
  2. |*                                       *|
  3. |*  utils.c:    A version of Tetris to run on Linux SVGAlib console.       *|
  4. |*        This module supplies all the function that I will need,    *|
  5. |*        but which are not intrinsically a part of Tetris itself.   *|
  6. |*                                       *|
  7. |*  Authors:    Mike Taylor (mirk@uk.ac.warwick.cs) &               *|
  8. |*        Arturo Espinosa (arturo@nuclecu.unam.mx)           *|
  9. |*  Started:    Fri May 26 12:26:05 BST 1989 (tetris for terminals)       *|
  10. |*            Dic 1, 1995 (pictetris)                       *|
  11. |*                                       *|
  12. \***************************************************************************/
  13.  
  14. #include <varargs.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <jlib.h>
  18. #include <strings.h>
  19. #include <sys/types.h>
  20. #include <sys/time.h>
  21. #include <errno.h>
  22.  
  23. /* Stuff needed to run under Linux */
  24. char* l_rindex (const char* s, int c)
  25. {return strrchr (s, c);}
  26.  
  27. #include "pictetris.h"
  28. #include "utils.h"
  29. #include "screen.h"
  30.  
  31. /*-------------------------------------------------------------------------*/
  32.  
  33. extern char *rindex ();
  34. extern char *getenv ();
  35.  
  36. /***************************************************************************\
  37. |*                                       *|
  38. |*  The function basename() acts like the UNIX(tm) command of the same       *|
  39. |*  name.  It takes as its argument a string, and returns the last path-   *|
  40. |*  component of that string, (ie, the section after the last '/'), or       *|
  41. |*  the whole string if it has no '/'.                       *|
  42. |*                                       *|
  43. \***************************************************************************/
  44.  
  45. char *basename (name)
  46.   char *name;
  47. {
  48.   char *slash;
  49.   if (slash = l_rindex (name, '/'))
  50.     return (slash+1);
  51.   else
  52.     return (name);
  53. }
  54.  
  55. /***************************************************************************\
  56. |*                                       *|
  57. |*  This is my home-made varargs-based version of C++'s neat function of   *|
  58. |*  the same name.  It saves all that tedious mucking about with static       *|
  59. |*  buffers which you sprintf into, then forget all about, by basically       *|
  60. |*  being a sprintf with its own statis storage.  It takes as arguments       *|
  61. |*  exactly the same things as printf(3), and returns a pointer to the       *|
  62. |*  resultant string.                               *|
  63. |*                                       *|
  64. \***************************************************************************/
  65.  
  66. /*VARARGS*/
  67. char *form (va_alist)
  68.   va_dcl
  69. {
  70.   va_list pvar;
  71.   char *fmt_string;
  72.   static char result[LINELEN];
  73.   
  74.   va_start (pvar);
  75.   fmt_string = va_arg (pvar, char*);
  76.   (void) vsprintf (result, fmt_string, pvar);
  77.   va_end (pvar);
  78.   return (result);
  79. }
  80.  
  81. /***************************************************************************\
  82. |*                                       *|
  83. |*  This is yer bog-standard "print a message and quit" function, except   *|
  84. |*  that it checks to see if we are in curses(3x), and if so, takes us       *|
  85. |*  out before doing its stuff.     The arguments are an integer, the exit       *|
  86. |*  status, and a string containing an error report, to which will be       *|
  87. |*  prepended the program name when it is printed.  If the status code       *|
  88. |*  is LE_OK, (ie. nothing went wrong), no message is printed.           *|
  89. |*                                       *|
  90. \***************************************************************************/
  91.  
  92. void die (status, line)
  93.   int status;
  94.   char *line;
  95. {
  96.   if (in_curses) {
  97.     myrefresh ();
  98.      kb_closedown();
  99.      screen_restore_video_mode();
  100.   }
  101.  
  102.   if (status != LE_OK)
  103.     (void) printf ("%s: %s\n", prog_name, line);
  104.  
  105. #ifndef LOCKF
  106.   (void) unlink (LOCK_FILE);    /* Just in case :-) */
  107. #endif /* LOCKF */
  108.   exit (status);
  109. }
  110.  
  111. /*-------------------------------------------------------------------------*/
  112.